﻿using System.Windows;
using System.Windows.Data;

namespace CodeAngel.UI.Extensions
{
    public static class BindExtensions
    {
        /// <summary>
        /// Binds the property on this elemeent to the path on this element.
        /// </summary>
        public static Binding Bind(this FrameworkElement element, DependencyProperty targetProperty, string sourcePath)
        {
            return Bind(element, targetProperty, sourcePath, element);
        }

        /// <summary>
        /// Binds the property on this elemeent to the path on the source object.
        /// </summary>
        public static Binding Bind(this FrameworkElement element, DependencyProperty targetProperty, string sourcePath, object source, BindingMode mode = BindingMode.OneWay)
        {
            Binding ThisBinding = new Binding(sourcePath);
            if (source != null) ThisBinding.Source = source;
            ThisBinding.Mode = mode;
            element.SetBinding(targetProperty, ThisBinding);
            return ThisBinding;
        }

    }
}
